package com.gitee.wsl.reflect.func.library.loader

import com.gitee.wsl.reflect.func.library.Library
import com.gitee.wsl.reflect.func.library.LibraryLoader
import kotlin.reflect.KFunction

/**
 * A Quarkdown function that can be exported via a [FunctionLibraryLoader].
 */
typealias ExportableFunction = KFunction<*>


/**
 * A [com.gitee.wsl.reflect.func.library.LibraryLoader] that loads a library from a set of sources at once.
 * @param name name to assign to the library
 * @param loader strategy to load libraries from a single source with
 */
class MultiLibraryLoader<S>(
    private val name: String,
    private val loader: LibraryLoader<S>,
) : LibraryLoader<Set<S>> {
    override fun load(source: Set<S>): Library {
        return Library(
            this.name,
            source.asSequence()
                .flatMap { loader.load(it).functions }
                .toSet(),
        )
    }
}